import { createRouter, createWebHistory } from 'vue-router'

var routes = [
  {
    path: '/',
    component: () => import('@/views/Login.vue')
  },
  {
    path: '/register',
    component: () => import('@/views/Register.vue')
  },
  {
    path: '/backoffice',
    component: () => import('@/views/Index.vue'),
    children: [
      {
        path: 'dashboard/firstspeed',
        name: 'FirstSpeed',
        component: () => import('@/views/DashboardOneSpeed.vue')
      },
      {
        path: 'dashboard/secondspeed',
        name: 'SecondSpeed',
        component: () => import('@/views/DashboardTwoSpeed.vue')
      },
      {
        path: 'dashboard/thirdspeed',
        name: 'ThirdSpeed',
        component: () => import('@/views/DashboardThreeSpeed.vue')
      },
      {
        path: 'setting/personality',
        name: 'Personality',
        component: () => import('@/views/PersonalitySetting.vue')
      }
    ]
  },
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

router.beforeEach((to, from, next) => {
  var loginStatus = localStorage.getItem('user')
  if (to.path !== '/' && to.path !== '/register' && !loginStatus) {
    next('/')
  } else {
    next()
  }
})

export default router
